package com.example.larouzey.beepproject;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.cbtService.AndroidSDK.BeepService;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private Button bs,bt,bu,bd;
    BeepService beepService;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        beepService=new BeepService();
        beepService._init();

        bs=(Button)findViewById(R.id.button1);
        bu=(Button)findViewById(R.id.button1);
        bd=(Button)findViewById(R.id.button1);
        bt=(Button)findViewById(R.id.button1);

        bs.setOnClickListener(this);
        bu.setOnClickListener(this);
        bd.setOnClickListener(this);
        bt.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        int a=0;
        switch (view.getId()){
            case R.id.button1:
                beepService.PWMPlay(1);
                break;
            case R.id.button2:
                if(a>0 && a<=20) {
                    a += a;
                    beepService.PWMPlay(a);
                }else{
                    Toast.makeText(this,"已调至最大值",Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.button3:
                if(a>0 && a<=20) {
                    a -= a;
                    beepService.PWMPlay(a);
                }else{
                    Toast.makeText(this,"已调至最低频率",Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.button4:
                beepService.PWMStop();
                break;
        }
    }
}
